var basePopupArr = [];
var baseMarkArr = [];
//添加mark以及mark的popup函数
function addMarkAndPopup(baleInfoArr,group) {
	debugger;
	map.events.unregister('moveend', map,mapMoveEndEventCallback);
	closeForBaseInvestigate();
	basePopupArr = [];
    baseMarkArr = [];
    var featurelayer = new OpenLayers.Layer.Vector("演示mark图层");
    var layerForMark = new OpenLayers.Layer.Markers("阴影效果图层");
    closeForBaseInvestigate.featurelayer = featurelayer;
    closeForBaseInvestigate.layerForMark = layerForMark;
    map.addLayer(featurelayer);
    map.addLayer(layerForMark);
    //存放popup的数组，针对蒙版定位展开时利用
    //通过下标和mark相应对
   
    ////添加feature
    for (var i = 0; i < baleInfoArr.length; i++) {
       
       
        var type = "";
        var imgheight = 8;
        if(group=="group"){
        	type =  "group_"+baleInfoArr[i].jbqk0102;
        	
        }else{
        	type = baleInfoArr[i].jbqk0100.substring(6,8);
        	imgheight = 16;
        }
        var size = new OpenLayers.Size(8, imgheight);	
        var sizeForShadow = new OpenLayers.Size(21, 14);
        var offsetForShadow = new OpenLayers.Pixel((size.w / 4-5), -2);
        var icon = new OpenLayers.Icon("image/zhdType/"+type+".png", size);
        var data = { icon: icon };
        var point = lonLat2Mercator(baleInfoArr[i].jbqk0120, baleInfoArr[i].jbqk0130);
        //添加阴影
        var iconForShadow = new OpenLayers.Icon('image/zhdType/marker_shadow.png',sizeForShadow,offsetForShadow);
        layerForMark.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(point.x, point.y), iconForShadow));
        createMarkAndPopup(layerForMark, featurelayer, data,baleInfoArr[i]);
    }
}
//制造mark和popup
function createMarkAndPopup(layerForMark, featurelayer, data, obj) {
     var point = lonLat2Mercator(obj.jbqk0120, obj.jbqk0130);
    //制造要素
    var feature = new OpenLayers.Feature(featurelayer, new OpenLayers.LonLat(point.x, point.y), data);
    //通过要素去制造mark
    var mark = feature.createMarker();
    layerForMark.addMarker(mark);
    baseMarkArr.push(mark);
    //通过要素去制造popup
    
    var popupContentHTML = packageContent(obj);
    
    var popup = new OpenLayers.Popup.NestFramedCloud(obj.jbqk0100+obj.jbqk0102, new OpenLayers.LonLat(point.x,point.y), new OpenLayers.Size(280, 120), popupContentHTML, null, true, null);
    popup.div.onclick = function(){
		top.showCurrentPopup(map,popup);
	}
    popup.hide();
    map.events.unregister('moveend', map,mapMoveEndEventCallback);
   	map.addPopup(popup);
   	
    //点击mark之后出popup，注册事件
     
    mark.events.register("mousedown", mark, mousedown);
    function mousedown(e) {
    	
        popup.toggle();
        //OpenLayers.Event.stop(e); 
    }
    basePopupArr.push(popup);
   // imageRes= [];
  //  var data = {"id":obj.jbqk0100};
    //var url = baseUrl + "Query/queryBaseInvestigateImageById";
    //$.post(url, data, queryBaseInvestigateImageByIdCallBack);
}
//组装popup内容的方法
function packageContent(obj) {
    var url = "";
  var jcurl = "";
  var type = obj.jbqk0100.substring(6,8);
  var groupNum = obj.jbqk0102;
  var groupName = getOperTypeZhdByCode(groupNum);
  var baseUrl= '';
  switch(groupNum){
  case "1":
  case "2":
  	baseUrl = 'findJCDCDetailsByCodeType_'+type+'.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'&groupNum='+groupNum;
  	break;
  case "3":
	baseUrl = 'findJCDCDetailsByCodeType_yjdc.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'&groupNum='+groupNum;
	break;
  case "4":
	baseUrl = 'findJCDCDetailsByCodeType_qcqf.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'&groupNum='+groupNum;
	break;
  case "5":
	baseUrl = 'findJCDCDetailsByCodeType_zdzq.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'&groupNum='+groupNum;
	break;
 case "6":
	baseUrl = 'findJCDCDetailsByCodeType_yjjc.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'&groupNum='+groupNum;
	break;
  
  }
   var context = '<div  style="color:#056F89;width:280px; height:140px;font-size:13px">' +
                    '<div  style="height:15px;width:280px;position:absolute; top:0px;margin-top:0;">' +
                    '<div style="width:200px;position:absolute;" >' +
                        '<label style=" font-size:13px; font-weight:bold;">' + obj.jbqk0110 + '</label>' +
                    '</div>' +
                   
                    '</div>' +
                    '<div style="height:1px; width:280px; background:#CECECE; margin-top:15px;right:0;"></div>' +
                    '<div style="height:88px;margin-top:15px;">' +
                    '<div style="position:absolute;top:25px;width:140px; height:88px; padding:4px 0;">' +
                     '<label>灾点类别：</label>' +
					'<label>' + groupName + '</label>' +
					'<br/>' +
                    '<label>所在乡镇：</label>' +
					'<label>' + obj.jbqk0140 + '</label>' +
					'<br/>' +
					'<label>所在村：</label>' +
					'<label>' + obj.jbqk0150 + '</label>' +
					'<br/>' +
					'<label>所在组：</label>' +
					'<label>' + obj.jbqk0160 + '</label>' +
					'</div>' +
                        '<img id="'+obj.jbqk0100+'image" onclick=openInfo("'+obj.jbqk0110+'","'+obj.jbqk0170+'","'+obj.jbqk0180+'","'+obj.jbqk0102+'") src="uploadfolder/simple/'+getZhdImageAndFilePathByCode(obj.jbqk0102)+'/image/'+obj.jbqk0180+'" title="浏览图片" style="position:absolute;top:35px;cursor:pointer;margin:0 0 0 0px;height:88px;right:15px;width:110px;border:1px solid #333333;"></img>' +
                    '</div>' +
                   '<div style="position:absolute; width:270px;margin-top:10px">' +
                        '<div style="position:absolute; width:65px;height:15px;margin-left:5px;">' +
					        '<a href='+baseUrl+' target="_blank" style="color:#054d9f;">基础信息</a>' +
                        '</div>' +
                        '<div style="position:absolute; width:65px;height:15px;margin-left:75px;">' +
					        '<a href="findFzyaDetailsByCode.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'"  target="_blank" style="color:#054d9f;">防灾预案</a>' +
                        '</div>' +
                        '<div style="position:absolute; width:65px;height:15px;margin-left:150px;">' +
					        '<a href="findYjdcDetailsByCode.shtml?code='+ obj.jbqk0100+'&zhdName='+obj.jbqk0110+'" target="_blank" style="color:#054d9f;">应急调查</a>' +
                        '</div>' +
                        
                    '</div>' +
                    '</div>' +
                    '</div>' +
                '</div>';
    return context;
}
//点击灾害点名称时候调用的函数
function toLocation(index,p_lon,p_lat) {
	var lon = Number(p_lon) ;
	var lat = Number(p_lat);
	
	var point = lonLat2Mercator(lon,lat);
	map.setCenter(new OpenLayers.LonLat(point.x,point.y));
	//map.setCenter(new OpenLayers.LonLat(12799839.008522447,3551570.0822424218), 6);
	basePopupArr[index].toggle();
	top.showCurrentPopup(map,basePopupArr[index]);
}
//删除关闭对话框时图层上mark
function closeForBaseInvestigate() {
	
    if (closeForBaseInvestigate.layerForMark != null && closeForBaseInvestigate.featurelayer != null) {
       map.removeLayer(closeForBaseInvestigate.layerForMark);
       map.removeLayer(closeForBaseInvestigate.featurelayer);
       closeForBaseInvestigate.layerForMark = null;
       closeForBaseInvestigate.featurelayer = null;
       removePopupsByArray(basePopupArr);
   }
  
}
//打开灾害点简介信息
function openInfo(name,info,url,type){
	window.open("lookIntroduce.shtml?name="+encodeURI(name)+"&conURL="+encodeURI(info)+"&imgURL="+encodeURI(url)+"&fileName="+getZhdImageAndFilePathByCode(type));
}